<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
<input type="button" value="全选" id="btn1">
<input type="button" value="反选" id="btn2"><br>
<input type="checkbox">吃饭
<input type="checkbox">睡觉
<input type="checkbox">唱歌

</body>
<script>

    document.getElementById("btn1").onclick = function () {
        let cbs = document.querySelectorAll("input[type='checkbox']");
        for (let elements of cbs) {
            elements.checked = true
        }
    };
    document.getElementById("btn2").onclick = function () {
        let cbs = document.querySelectorAll("input[type='checkbox']");
        for (let elements of cbs) {
            elements.checked = !elements.checked
        }
    }
</script>
</html>

